/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control.dao;

import BD.CriaConexao;
import Relatorios.RelatorioMet;
import control.dao.metodosOperacao;
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

/**
 *
 * @author Andre
 */
public class NotaFiscal {

    private Connection conexao;

    public NotaFiscal() {
        try {
            this.conexao = CriaConexao.getConexao();
        } catch (SQLException ex) {
            Logger.getLogger(NotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void gerar(String adober, String nome, int cod_dvd) {

        Connection con = null;
        try {
            con = (Connection) CriaConexao.getConexao();
        } catch (SQLException ex) {
            Logger.getLogger(NotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
        }

        HashMap parametros = new HashMap();

        CriaConexao Con = new CriaConexao();
        RelatorioMet obm = new RelatorioMet();

        File f = new File(adober + "/Notas Fiscais");
        f.delete();
        File dir2 = new File(adober + "/Notas Fiscais");
        dir2.mkdir();
        String adober2;
        adober2 = String.valueOf(dir2);

        parametros.put("cod_dvd", cod_dvd);
        
        JasperPrint jp = null;
        try {
            jp = JasperFillManager.fillReport("./src/Relatorios/NotaFiscal.jasper", parametros, con);
        } catch (JRException ex) {
            Logger.getLogger(NotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            JasperExportManager.exportReportToPdfFile(jp, adober2 + "/NF_" + nome + ".pdf");
        } catch (JRException ex) {
            Logger.getLogger(NotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
